<template>
	<view class="content">
		<nav-bars bgColor="transparent" title="促销商品" fontColor="#000"></nav-bars>
		<view class="wrapper">
			<view class="goodsBox" v-if="goodsList.length>0">
				<view class="goodsItem flex" v-for="(item,index) in goodsList" :key="index"
					@click="goSkip('/pagesFour/activity/productGoods/goodsDetails?id='+item.id)">
					<view class="goods-cover">
						<image :src="item.main_imgurl">
						</image>
					</view>
					<view class="goods-dateils">
						<view class="columnTop flex">
							<view class="title text-ellipsis">
								{{item.product_title}}
								<view class="subTitle">{{item.subtitle}}</view>
							</view>
							<view class="shareIcon">
								<image :src="`${baseImg}/static/activity/share-icon.png`"></image>
							</view>
						</view>
						<view class="bottomBox flex">
							<view class="pricr flex">
								<text>￥{{item.price}}</text>
							</view>
							<view class="sidebarRight">
								商品库存{{item. num || 0}}
							</view>
						</view>
					</view>
				</view>
				<u-loadmore :status="statusLoading" :icon-type="iconType" :load-text="loadText" />
			</view>
			<view class="notList" v-if="goodsList.length<=0">
				<image :src="`${baseImg}/static/constr/notList.png`" mode=""></image>
				空空如也
			</view>
		</view>
	</view>
</template>

<script>
	import service_mall from '@/service/mall.js'
	export default {
		data() {
			return {
				statusLoading: 'loadmore',
				iconType: 'flower',
				loadText: {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '到底了~'
				},
				baseImg: this.$static,
				page: 1,
				pagesize: 10,
				goodsList: [],
			}
		},
		onLoad() {
			this.getProduct();
		},
		methods: {
			getProduct() {
				let params = {
					page: this.page,
					pagesize: this.pagesize
				}
				this.statusLoading = 'loading'
				service_mall.activityGoods(params).then(res => {
					if (res.code == 1) {
						let data = res.data.products
						if (!data.length) {
							this.statusLoading = 'nomore'
						} else if (data.length < this.pagesize) {
							this.statusLoading = 'nomore'
						} else {
							this.statusLoading = 'loading'
						}
						this.goodsList = this.goodsList.concat(data)
					}
				})
			},
			goSkip(url) {
				uni.navigateTo({
					url: url
				});
			},
		},
		onReachBottom() {
			this.page++;
			if (this.statusLoading == 'loading') {
				this.getProduct();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 100%;
		height: 100%;

		.wrapper {
			width: 100%;

			.goodsBox {
				width: 96%;
				margin: 60rpx auto;
				position: relative;

				.goodsItem {
					width: 100%;
					height: auto;
					margin-bottom: 60rpx;

					.goods-cover {
						width: 28%;

						image {
							width: 190rpx;
							height: 190rpx;
							border-radius: 10rpx;
						}
					}

					.goods-dateils {
						width: 72%;
						margin-left: 20rpx;
                        position: relative;
						.columnTop {
							width: 100%;
							justify-content: space-between;
							.title {
								width: 450rpx;
								height: auto;

								.subTitle {
									margin: 10rpx 0 0 4rpx;
									color: #717171;
								}
							}

							.shareIcon {
								width: 68rpx;
								height: 68rpx;

								image {
									width: 100%;
									height: 100%;
									margin-top: -6px;
								}
							}
						}

						.bottomBox {
							align-items: flex-end;
							justify-content: space-between;
							position: absolute;
							bottom:20rpx;
							height: 50rpx;

							.pricr {
								width: 350rpx;
								height: auto;
							}

							.sidebarRight {
								color: #A6A6A6;
								padding-right: 20rpx;
							}
						}

					}



				}
			}
		}

		// 没有数据
		.notList {
			position: absolute;
			top: 0;
			left: 0;
			right: 0;
			bottom: 0;
			margin: auto;
			height: 400rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
			width: 426rpx;

			image {
				width: 426rpx;
				height: 356rpx;
				margin-bottom: 40rpx;
			}

			font:500 40rpx/56rpx PingFang SC;
			color: #333;
		}

		.text-ellipsis {
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
		}
	}
</style>
